package org.fastsyncer.connector.oracle;

import org.fastsyncer.connector.config.DatabaseConfig;
import org.fastsyncer.connector.config.SqlConfig;
import org.fastsyncer.connector.constant.DatabaseConstant;
import org.fastsyncer.connector.database.AbstractDatabaseConnector;

public final class OracleConnector extends AbstractDatabaseConnector {

    @Override
    public SqlConfig getSqlConfig(DatabaseConfig config, String table, String queryFilter) {
        // 查询元信息 SELECT * FROM USER WHERE ROWNUM = 0
        String metaSQL = new StringBuilder().append("SELECT * FROM ").append(table).append(" WHERE").append(DatabaseConstant.ORACLE_PAGE_SQL_NULL).toString();
        // 求数据总量 SELECT * FROM USER WHERE ID='123'
        String countSQL = new StringBuilder().append("SELECT * FROM ").append(table).append(queryFilter).toString();
        return new SqlConfig(metaSQL, countSQL);
    }

    @Override
    public String getPageSql(DatabaseConfig config, String table, String sql) {
        // Oracle 分页查询
        return DatabaseConstant.ORACLE_PAGE_SQL_START + sql + DatabaseConstant.ORACLE_PAGE_SQL_END;
    }

}
